package cn.itheima.dao;

import cn.itheima.pojo.Sku;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;

public class SkuDaoImpl implements SkuDao {
    @Override
    public List<Sku> querySkuList() {

        Connection connection = null;
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;
        List<Sku> resultList = new ArrayList<>();
        try {
            Class.forName("com.mysql.jdbc.Driver");
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/luncen", "root", "root");
            String sql = "select * from tb_sku";
            preparedStatement = connection.prepareStatement(sql);
            resultSet = preparedStatement.executeQuery();
            while (resultSet.next()){
                Sku sku = new Sku();
                sku.setId(resultSet.getString("Id"));
                resultList.add(sku);
            }

        } catch (ClassNotFoundException | SQLException e) {
            e.printStackTrace();
        }

        return resultList;
    }
}
